package Exercise;

/**
 * Description：
 * Author: zhangc
 * Date：2017/8/6 16:06
 */
public class MaxSub {

    public static int getDis(int[] A, int n) {
        if (A == null || A.length <= 1)
            return 0;
        int min = A[ 0 ], max = A[ 1 ] - min;
        for (int i = 1; i < A.length; i++) {
            if (A[ i ] < min)
                min = A[ i ];
            else if (A[ i ] - min > max)
                max = A[ i ] - min;
        }
        return max;
    }

    public static void main(String[] args) {
        int[] ints = {1, -1, 3, 4, -5, 22, 12, -34, 33, 21};
        System.out.println(getDis(ints, 11));
    }

}
